package sjms.create.singleton;

public class Singleton_1 {
    public static void main(String[] args) {
        SingleTon s1 = SingleTon.getInstance();
        SingleTon s2 = SingleTon.getInstance();

        System.out.println(s1==s2);
        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());
    }
}

/**
 * 饿汉式——1
 * 通过类装载的机制保证实例只有一个，不会有多线程安全问题
 * 缺点是无法做到懒加载，可能造成内存浪费
 **/

class SingleTon{

    private SingleTon(){}

    private static final SingleTon instance = new SingleTon();

    public static SingleTon getInstance(){
        return instance;
    }
}